package yx.action;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.InvitationReplyServiceInt;
import yx.vo.InvitationReplyVO;
import yx.vo.JsonVO;
import yx.vo.UserVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "invitationReplyAction")
public class InvitationReplyAction extends BaseAction implements ModelDriven<InvitationReplyVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(InvitationReplyAction.class);

	private InvitationReplyVO invitationReply = new InvitationReplyVO();

	@Override
	public InvitationReplyVO getModel() {
		return invitationReply;
	}

	private InvitationReplyServiceInt invitationReplyService;

	public InvitationReplyServiceInt getInvitationReplyService() {
		return invitationReplyService;
	}

	@Autowired
	public void setInvitationReplyService(InvitationReplyServiceInt invitationReplyService) {
		this.invitationReplyService = invitationReplyService;
	}

	public void queryInvitationReply() {
		super.writeJson(invitationReplyService.datagrid(invitationReply));
	}

	public void addInvitationReply() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		UserVO user = (UserVO) session.getAttribute("LOGIN_USER");
		invitationReply.setReplierId(user.getId());
		invitationReply.setReplierName(user.getRealName());
		JsonVO j = new JsonVO();
		try {
			InvitationReplyVO u = invitationReplyService.save(invitationReply);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void removeInvitationReply() {
		invitationReplyService.remove(invitationReply.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void editInvitationReply() {
		InvitationReplyVO u = invitationReplyService.edit(invitationReply);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}

}
